//
//  UITabBarController+LCAddition.m
//
//  Created by admin on 2016/12/26.
//  Copyright © 2016年 LC. All rights reserved.
//

#import "UITabBarController+LCAddition.h"
#import "LCNavigationController.h"

@implementation UITabBarController (LCAddition)

+ (UIViewController *)lc_navControllerWithSbName:(NSString *)sbName title:(NSString *)title imageName:(NSString *)imageName{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:sbName bundle:nil];
    
    UIViewController *controller = [sb instantiateInitialViewController];
    
    LCNavigationController *navController = [[LCNavigationController alloc] initWithRootViewController:controller];
    
    return [self controllerWithNavCotroller:navController title:title imagName:imageName];
}

+(UIViewController *)lc_navControllerWithClassName:(NSString *)clzName title:(NSString *)title imageName:(NSString *)imageName{
    Class clz = NSClassFromString(clzName);
    UIViewController *controller = [[clz alloc] init];
    LCNavigationController *navController = [[LCNavigationController alloc] initWithRootViewController:controller];
    
    return [self controllerWithNavCotroller:navController title:title imagName:imageName];
}

+(UIViewController *)controllerWithNavCotroller:(UIViewController *)navController title:(NSString *)title imagName:(NSString *)imageName{
    navController.title = title;
    navController.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navController.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navController.tabBarItem.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);

    [navController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor darkGrayColor]} forState:UIControlStateSelected];//将字 变成深灰颜色

    return navController;
}


/**
 添加导航控制器, 默认导航条样式上面电池条为黑色风格
 */
+(UINavigationController *)lc_addChildControllerWithSbName:(NSString *)sbName title:(NSString *)title imageName:(NSString *)imageName{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:sbName bundle:nil];
    UIViewController *controller = [sb instantiateInitialViewController];
    LCNavigationController *navController = [[LCNavigationController alloc] initWithRootViewController:controller];
    controller.title = title;
    controller.tabBarItem.image = [UIImage imageNamed:imageName];//未选中的图片样式
    
    controller.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@",[imageName stringByReplacingOccurrencesOfString:@"_nor" withString:@"_prs"]]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//选中的图片样式
    controller.tabBarItem.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    
    [controller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:defaultFuYinColor} forState:UIControlStateSelected];//将字 变成red颜色
    
    return navController;
}

/**
 添加导航控制器, 默认导航条样式上面电池条为白色风格
 */
+(UINavigationController *)lc_addChildControllerWith:(NSString *)clzName title:(NSString *)title imageName:(NSString *)imageName{
    Class clz= NSClassFromString(clzName);
    UIViewController *controller = [[clz alloc] init];
    LCNavigationController *nav = [[LCNavigationController alloc] initWithRootViewController:controller];
    controller.title = title;
    
    controller.tabBarItem.image = [UIImage imageNamed:imageName];//未选中的图片样式
    
    controller.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//选中的图片样式
    controller.tabBarItem.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);

    [controller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor darkGrayColor]} forState:UIControlStateSelected];//将字 变成深灰颜色
    
    
    return nav;
}
@end
